<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>操作日志</title>
    <div th:replace="common/base"></div>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div style="margin: 0px 10px">
            <div class="layui-form layui-form-pane" action="">
                <div class="layui-form-item" style="margin: 0px">
                    <div class="layui-inline">
                        <label class="layui-form-label">关键字</label>
                        <div class="layui-input-inline">
                            <input type="text" name="keyword" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" type="submit" class="layui-btn layui-btn-primary" lay-submit
                                lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <script type="text/html" id="toolbarLog">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"><i
                        class="layui-icon">&#xe640;</i>清空
                </button>
            </div>
        </script>

        <table id="logTable" lay-filter="logTable"></table>
    </div>
</div>
<div th:replace="common/baseJS"></div>
<script th:inline="none">
    layui.use(['form', 'opTable', 'table', 'ab'], function () {
        var $ = layui.jquery,
            form = layui.form,
            opTable = layui.opTable,
            table = layui.table,
            ab = layui.ab;

        var logOpTable = opTable.render({
            elem: '#logTable',
            url: '/monitor/log/findPage?logType=INFO',
            toolbar: '#toolbarLog',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: 'numbers'},
                {field: 'id', width: 80, title: 'ID', hide: true},
                {field: 'username', title: '用户名'},
                {field: 'requestIp', title: 'IP'},
                {field: 'address', title: 'IP来源'},
                {field: 'description', title: '描述'},
                {field: 'browser', title: '浏览器'},
                {
                    field: 'time', title: '请求耗时', templet: function (d) {
                        return '<span class="layui-badge layui-bg-blue">' + d.time + 'ms</span>';
                    }
                },
                {
                    field: 'createTime', title: '创建时间', templet: function (d) {
                        if (d.createTime != null) {
                            return ab.dateUtil.format(d.createTime, "yyyy-MM-dd hh:mm:ss");
                        }
                        return '';
                    }
                }
            ]],
            openCols: [
                {field: 'method', title: '请求方法'},
                {field: 'params', title: '请求参数'},
            ],
            response: {
                statusName: 'status', //规定数据状态的字段名称，默认：code
                statusCode: 200, //规定成功的状态码，默认：0
                msgName: 'hint', //规定状态信息的字段名称，默认：msg
                countName: 'total', //规定数据总数的字段名称，默认：count
                dataName: 'rows' //规定数据列表的字段名称，默认：data
            },
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            logOpTable.reload({
                page: {curr: 1},
                where: data.field
            }, 'data');

            return false;
        });

        // /* 表格头工具栏点击事件 */
        table.on('toolbar(logTable)', function (obj) {
            if (obj.event === 'delete') {  // 监听删除操作
                ab.util.deleteForm({
                    url: "/monitor/log/del",// 请求地址
                    type: "delete",// 请求提交方式
                    data: JSON.stringify({logType: "INFO"}),// 发送回去的数据 JSON.stringify(data)
                    success: function (data) {
                        $("#btnSearch").click();
                    }
                });
            }
        });
    });
</script>

</body>
</html>